#include<iostream>
using std::cout;
using std::endl;

#include"CPqueue.h"
void Consumer(CPqueue& cp, const std::string& name)
{
	while (1)
	{
		FUNC func;
		cp.PopTask(func);
		//cout << "Consumer get task" << endl;

		//sleep(1);
		func(name);
	}
}

void Productor(CPqueue& cp)
{
	while (1)
	{
		cp.PushTask(Task);
		cout << "Productor push task" << endl;

        sleep(1);
		//Sleep(100);
	}
}

int main()
{
	CPqueue cp(5);
	std::thread t1(Productor, std::ref(cp));
	std::thread t2(Consumer, std::ref(cp), "Consumer1");
	std::thread t3(Consumer, std::ref(cp), "Consumer2");
	std::thread t4(Consumer, std::ref(cp), "Consumer3");
	
	/*while (1)
	{
		Sleep(1);
		fflush(stdout);
	}*/
    cout << "1" << endl;
    std::this_thread::sleep_for(std::chrono::milliseconds(1500));
    cout << "2" << endl;

	t1.join();
	t2.join();
	t3.join();
	t4.join();

	return 0;
}
